layui.define([ 'form', 'laydate', 'table','keyInformationApi'], function(exports) {
    var form = layui.form;
    var keyInformationApi = layui.keyInformationApi;
    var index = layui.index;
    var view = {
        init:function(){
	        Lib.initGenrealForm($("#updateForm"),form);
	        this.initSubmit();
        },
        initSubmit:function(){
            $("#updateButton").click(function(){
                form.on('submit(form)', function(){
                    /**
                     * 获取文件
                     */

                    var newDocumentsScanned = Common.fileRequire("#newDocumentsScannedDataList");
                    var oldDocumentsScanned = Common.fileRequire("#oldDocumentsScannedDataList");
                    if(newDocumentsScanned){
                        Common.alert("新的证件扫描件附件必须上传");
                    }else if(oldDocumentsScanned) {
                        Common.alert("旧的证件扫描件附件必须上传");
                    }else {
                        keyInformationApi.update($('#updateForm'), function () {
                            parent.window.dataReload();
                            Common.info("编辑保存成功");
                            Lib.closeFrame();
                        });
                    }
                });
            });

            $("#updateButton-PandD").click(function(){
                form.on('submit(form)', function(){
                    /**
                     * 获取文件
                     */

                    var newDocumentsScanned = Common.fileRequire("#newDocumentsScannedDataList");
                    var oldDocumentsScanned = Common.fileRequire("#oldDocumentsScannedDataList");
                    if(newDocumentsScanned){
                        Common.alert("新的证件扫描件附件必须上传");
                    }else if(oldDocumentsScanned) {
                        Common.alert("旧的证件扫描件附件必须上传");
                    }else {
                        Common.openConfirm("确认申报?", function () {
                            keyInformationApi.editandsave($('#updateForm'), function () {
                                parent.window.dataReload();
                                Common.info("编辑申报成功");
                                Lib.closeFrame();
                            });
                        }, null)
                    }
                });
            });
            $("#updateButton-cancel").click(function(){
                Lib.closeFrame();
            });


            $("#acceptance-termination").click(function(){
                form.on('submit(form)', function(){
                        Common.openConfirm("确认终止?", function () {
                            keyInformationApi.Admissibility($('#updateForm'), function () {
                                parent.window.dataReload();
                                Common.info("已终止");
                                Lib.closeFrame();
                            });
                        }, null);
                });
            });

            $("#acceptance-return").click(function(){
                form.on('submit(form)', function() {

                        Common.openConfirm("确认退回?", function () {
                        keyInformationApi.AdmissibleReturn($('#updateForm'), function () {
                            parent.window.dataReload();
                            Common.info("已退回");
                            Lib.closeFrame();
                        });
                    }, null);
                });
            });
            $("#acceptance-adopt").click(function(){ if(document.getElementById("handlingSuggestion").value.trim() == ''){                 $("#handlingSuggestion").val("通过");             }
                form.on('submit(form)', function(){
                    var f = function(){

                        Common.openConfirm("确认通过?", function () {
                    keyInformationApi.AcceptanceOK($('#updateForm'),function(){
                        parent.window.dataReload();
                        Common.info("已通过");
                        Lib.closeFrame();
                    });},null);
                    }
                    Common.validAll(f);
                });
            });
        }
            
    }
    exports('edit',view);
	
});